using System; 
using System.Text; 
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration; 
using System.Xml; 
using System.Xml.Serialization;
using SubSonic; 
using SubSonic.Utilities;

namespace Commerce.Common
{
	/// <summary>
	/// Strongly-typed collection for the CategoryLog class.
	/// </summary>
	[Serializable]
	public partial class CategoryLogCollection : ActiveList<CategoryLog,CategoryLogCollection> 
	{	   
		public CategoryLogCollection() {}

	}

	/// <summary>
	/// This is an ActiveRecord class which wraps the CategoryLog table.
	/// </summary>
	[Serializable]
	public partial class CategoryLog : ActiveRecord<CategoryLog>, IActiveRecord
	{
		#region .ctors and Default Settings
		
		public CategoryLog()
		{
		  SetSQLProps();
		  InitSetDefaults();
		  MarkNew();
		}

		
		private void InitSetDefaults() { SetDefaults(); }

		
		public CategoryLog(bool useDatabaseDefaults)
		{
			SetSQLProps();
			if(useDatabaseDefaults)
				ForceDefaults();
			MarkNew();
		}

        
		public CategoryLog(object keyID)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByKey(keyID);
		}

		 
		public CategoryLog(string columnName, object columnValue)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByParam(columnName,columnValue);
		}

		
		protected static void SetSQLProps() { GetTableSchema(); }

		
		#endregion
		
		#region Schema and Query Accessor	
		public static Query CreateQuery() { return new Query(Schema); }

		public static TableSchema.Table Schema
		{
			get
			{
				if (BaseSchema == null)
					SetSQLProps();
				return BaseSchema;
			}

		}

		
		private static void GetTableSchema() 
		{
			if(!IsSchemaInitialized)
			{
				//Schema declaration
				TableSchema.Table schema = new TableSchema.Table("CategoryLog", TableType.Table, DataService.GetInstance("dashCommerce"));
				schema.Columns = new TableSchema.TableColumnCollection();
				schema.SchemaName = @"dbo";
				//columns
				
				TableSchema.TableColumn colvarCategoryLogID = new TableSchema.TableColumn(schema);
				colvarCategoryLogID.ColumnName = "CategoryLogID";
				colvarCategoryLogID.DataType = DbType.Int32;
				colvarCategoryLogID.MaxLength = 0;
				colvarCategoryLogID.AutoIncrement = true;
				colvarCategoryLogID.IsNullable = false;
				colvarCategoryLogID.IsPrimaryKey = true;
				colvarCategoryLogID.IsForeignKey = false;
				colvarCategoryLogID.IsReadOnly = false;
				colvarCategoryLogID.DefaultSetting = @"";
				colvarCategoryLogID.ForeignKeyTableName = "";
				schema.Columns.Add(colvarCategoryLogID);
				
				TableSchema.TableColumn colvarCategoryID = new TableSchema.TableColumn(schema);
				colvarCategoryID.ColumnName = "CategoryID";
				colvarCategoryID.DataType = DbType.Int32;
				colvarCategoryID.MaxLength = 0;
				colvarCategoryID.AutoIncrement = false;
				colvarCategoryID.IsNullable = false;
				colvarCategoryID.IsPrimaryKey = false;
				colvarCategoryID.IsForeignKey = true;
				colvarCategoryID.IsReadOnly = false;
				colvarCategoryID.DefaultSetting = @"";
				
					colvarCategoryID.ForeignKeyTableName = "Category";
				schema.Columns.Add(colvarCategoryID);
				
				TableSchema.TableColumn colvarLogID = new TableSchema.TableColumn(schema);
				colvarLogID.ColumnName = "LogID";
				colvarLogID.DataType = DbType.Int32;
				colvarLogID.MaxLength = 0;
				colvarLogID.AutoIncrement = false;
				colvarLogID.IsNullable = false;
				colvarLogID.IsPrimaryKey = false;
				colvarLogID.IsForeignKey = true;
				colvarLogID.IsReadOnly = false;
				colvarLogID.DefaultSetting = @"";
				
					colvarLogID.ForeignKeyTableName = "Log";
				schema.Columns.Add(colvarLogID);
				
				BaseSchema = schema;
				//add this schema to the provider
				//so we can query it later
				DataService.Providers["dashCommerce"].AddSchema("CategoryLog",schema);
			}

		}

		#endregion
		
		#region Props
		
		  
		[XmlAttribute("CategoryLogID")]
		public int CategoryLogID 
		{
			get { return GetColumnValue<int>(Columns.CategoryLogID); }

			set { SetColumnValue(Columns.CategoryLogID, value); }

		}

		  
		[XmlAttribute("CategoryID")]
		public int CategoryID 
		{
			get { return GetColumnValue<int>(Columns.CategoryID); }

			set { SetColumnValue(Columns.CategoryID, value); }

		}

		  
		[XmlAttribute("LogID")]
		public int LogID 
		{
			get { return GetColumnValue<int>(Columns.LogID); }

			set { SetColumnValue(Columns.LogID, value); }

		}

		
		#endregion
		
		
			
		
		#region ForeignKey Properties
		
		/// <summary>
		/// Returns a Log ActiveRecord object related to this CategoryLog
		/// 
		/// </summary>
		public Commerce.Common.Log Log
		{
			get { return Commerce.Common.Log.FetchByID(this.LogID); }

			set { SetColumnValue("LogID", value.LogID); }

		}

		
		
		#endregion
		
		
		
		//no ManyToMany tables defined (0)
		
        
        
		#region ObjectDataSource support
		
		
		/// <summary>
		/// Inserts a record, can be used with the Object Data Source
		/// </summary>
		public static void Insert(int varCategoryID,int varLogID)
		{
			CategoryLog item = new CategoryLog();
			
			item.CategoryID = varCategoryID;
			
			item.LogID = varLogID;
			
		
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}

		
		/// <summary>
		/// Updates a record, can be used with the Object Data Source
		/// </summary>
		public static void Update(int varCategoryLogID,int varCategoryID,int varLogID)
		{
			CategoryLog item = new CategoryLog();
			
				item.CategoryLogID = varCategoryLogID;
			
				item.CategoryID = varCategoryID;
			
				item.LogID = varLogID;
			
			item.IsNew = false;
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}

		#endregion
        
        
        
        #region Typed Columns
        
        
        public static TableSchema.TableColumn CategoryLogIDColumn
        {
            get { return Schema.Columns[0]; }

        }

        
        
        
        public static TableSchema.TableColumn CategoryIDColumn
        {
            get { return Schema.Columns[1]; }

        }

        
        
        
        public static TableSchema.TableColumn LogIDColumn
        {
            get { return Schema.Columns[2]; }

        }

        
        
        
        #endregion
		#region Columns Struct
		public struct Columns
		{
			 public static string CategoryLogID = @"CategoryLogID";
			 public static string CategoryID = @"CategoryID";
			 public static string LogID = @"LogID";
						
		}

		#endregion
		
		
		
	}

}

